<template>
  <div>
    <BasicTable @register="registerTable">
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              label: '删除',
              icon: 'ant-design:delete-outlined',
              color: 'error',
              onClick: handleDelete.bind(null, record),
            },
          ]"
        />
      </template>
      <template #image="{ record }">
        <div class="article-image">
          <Image :height="50" :src="record.cover" />
        </div>
      </template>
      <template #module="{ record }">
        <a @click="handleModule(record)">{{
          record.module.website.name + ' - ' + record.module.name
        }}</a>
      </template>
      <template #link="{ record }">
        <a :href="record.url" target="_blank" rel="noreferrer">{{ record.title }}</a>
      </template>
    </BasicTable>
  </div>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
  import { Image } from 'ant-design-vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { useGo } from '/@/hooks/web/usePage';
  import { getArticleList } from '/@/api/demo/media';

  import { columns, searchFormSchema } from './data';

  export default defineComponent({
    name: 'MediaArticle',
    components: { BasicTable, TableAction, Image },
    setup() {
      const go = useGo();
      const [registerTable, { reload }] = useTable({
        title: '采集文章',
        api: getArticleList,
        rowKey: 'id',
        columns,
        formConfig: {
          labelWidth: 120,
          schemas: searchFormSchema,
          autoSubmitOnEnter: true,
        },
        useSearchForm: true,
        showTableSetting: true,
        bordered: true,
        showIndexColumn: true,
      });

      function handleModule(record: Recordable) {
        go('/media/article/module/' + record.module_id);
      }

      return {
        registerTable,
        handleModule,
      };
    },
  });
</script>
